<template>
    <PublishRule v-model:rule="ruleObj" save-rule-btn-text="添加规则" @save:rule="addRuleFunc" type="add"></PublishRule>
</template>

<script lang="ts" setup>
    import { message } from "ant-design-vue";
    import PublishRule from "@/components/PublishRule.vue";
    import { esArtPublishRuleApi } from "@/api/esArticle";
    defineOptions({
        name: "AddPublishRule"
    });
    const ruleObj = reactive<PostPublishRuleParams>({
        custom_identifier: "index",
        rule_name: "",
        rule_type: 1,
        publish_type: 2,
        day_pub_num: 1,
        column_ids: [0],
        custom_attrs: ["random"],
        create_id: 0,
        author: "",
        week_option:[],
        source: "",
        module_id: 0,
        is_fb_domain: 0,
        publish_field_data: {},
        es_search: {
            body: { query: { bool: { must: [], should: [], must_not: [] } } },
            index: "",
            host: "",
            wyc: "",
            sum: 0,
            mustModeMap: {
                must: { conditions: [] },
                must_not: { conditions: [] },
                should: { conditions: [] }
            }
        },
        title_replace: {
            status: false,
            replace_rule: ""
        },
        content_replace: {
            status: false,
            replace_rule: ""
        },
        title_insert_kwd: {
            status: false,
            keywords: "",
            min_count: 1,
            max_count: 1,
            split_char: ",",
            region: 0,
            chance: 100
        },
        head_insert_kwd: {
            status: false,
            keywords: "",
            min_count: 1,
            max_count: 1
        },
        center_insert_kwd: {
            status: false,
            keywords: "",
            min_count: 1,
            max_count: 1,
            position_char: "p"
        },
        footer_insert_kwd: {
            status: false,
            keywords: "",
            min_count: 1,
            max_count: 1
        },
        insert_zuhe_img: {
            status: false,
            min_count: 1,
            max_count: 1,
            background: "",
            logo: "",
            pellucidity: 0.9,
            canvas_size: { height: 1200, width: 800 },
            font_color: "#000000",
            font_size: 16,
            text_position: 5,
            img_position: 5,
            logo_size: { height: 100, width: 100 },
            font_type: "",
            text: ""
        },
        insert_img: {
            status: false,
            directory: "",
            tags: [],
            min_count: 1,
            max_count: 1,
            esBody: {}
        },
        tag_keywords: {
            keywords: "",
            min_count: 1,
            max_count: 1
        },
        cms_keywords: {
            keywords: "",
            min_count: 1,
            max_count: 1
        }
    });
    const addRuleFunc = (rule: PostPublishRuleParams) => {
        esArtPublishRuleApi(rule, "post")
            .then((res) => {
                if (res.data.code === 200) {
                    message.success("操作成功!");
                } else {
                    // @ts-ignore
                    message.error(res.data.msg);
                }
            })
            .catch(() => {
                message.error("服务器错误！");
            });
    };
</script>

<style scoped lang="scss"></style>
